Skip to content

fix: handled MetricAgent plugin for multi matrix#4338

Open
Hardikl wants to merge 4 commits into
mainfrom
hl_sg
Open

fix: handled MetricAgent plugin for multi matrix#4338
Hardikl wants to merge 4 commits into
mainfrom
hl_sg

Conversation

@Hardikl

@Hardikl Hardikl commented Jul 2, 2026

Copy link
Copy Markdown
Contributor
image

Added supporting test cases as well.

Copilot AI review requested due to automatic review settings July 2, 2026 10:21
@cla-bot cla-bot Bot added the cla-signed label Jul 2, 2026
@Hardikl

Hardikl commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Validated with below template changes,

name:   Prometheus
query:  prometheus
object: # leave blank to disable prefixing exported metrics with object name

schedule:
  - data: 3m

counters:
  - node_cpu_seconds_total                                                => storagegrid_node_cpu_seconds_total
  - storagegrid_content_buckets_and_containers
  - storagegrid_content_objects
  - storagegrid_ilm_awaiting_client_objects
  - storagegrid_ilm_awaiting_total_objects
  - storagegrid_ilm_objects_processed
  - storagegrid_ilm_scan_objects_per_second
  - storagegrid_metadata_queries_average_latency_milliseconds
  - storagegrid_network_received_bytes
  - storagegrid_network_transmitted_bytes
  - storagegrid_node_cpu_utilization_percentage
  - storagegrid_private_ilm_awaiting_delete_objects
  - storagegrid_private_load_balancer_storage_request_body_bytes_bucket
  - storagegrid_private_load_balancer_storage_request_count
  - storagegrid_private_load_balancer_storage_request_time
  - storagegrid_private_load_balancer_storage_rx_bytes
  - storagegrid_private_load_balancer_storage_tx_bytes
  - storagegrid_private_s3_total_requests
  - storagegrid_s3_data_transfers_bytes_ingested
  - storagegrid_s3_data_transfers_bytes_retrieved
  - storagegrid_s3_operations_failed
  - storagegrid_s3_operations_successful
  - storagegrid_s3_operations_unauthorized
  - storagegrid_storage_utilization_data_bytes
  - storagegrid_storage_utilization_metadata_allowed_bytes
  - storagegrid_storage_utilization_metadata_bytes
  - storagegrid_storage_utilization_total_space_bytes
  - storagegrid_storage_utilization_usable_space_bytes

plugins:
  - JoinRest
  - MetricAgent:
      compute_metric:
        - storagegrid_storage_utilization_used_percent PERCENT storagegrid_storage_utilization_data_bytes storagegrid_storage_utilization_total_space_bytes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the MetricAgent plugin so compute_metric rules can operate when the required operands are split across multiple matrices (instead of assuming a single object-keyed matrix), and adjusts/adds unit tests to cover the multi-matrix scenario.

Changes:

  • Changed MetricAgent.actions to accept the full dataMap (map[string]*matrix.Matrix) rather than a single *matrix.Matrix.
  • Updated computeMetrics to select operand matrices per rule/operand (enabling multi-matrix support).
  • Updated the single-matrix test to run through Run(), and added a new multi-matrix test case.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
cmd/poller/plugin/metricagent/parse_rules.go Updates action function signature to accept the full matrix map.
cmd/poller/plugin/metricagent/metric_agent.go Passes dataMap through actions and updates compute logic for multi-matrix operands.
cmd/poller/plugin/metricagent/metric_agent_test.go Renames/updates existing test to call Run() and adds a multi-matrix test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/poller/plugin/metricagent/metric_agent_test.go Outdated
Comment thread cmd/poller/plugin/metricagent/metric_agent.go
Copilot AI review requested due to automatic review settings July 2, 2026 11:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread cmd/poller/plugin/metricagent/metric_agent.go Outdated
Comment thread cmd/poller/plugin/metricagent/metric_agent.go
Comment thread cmd/poller/plugin/metricagent/metric_agent_test.go
metricVal = a.getMetric(m, r.metricNames[i])
if metricVal != nil {
v, _ = metricVal.GetValueFloat64(instance)
if m[i] != nil && m[i].GetInstance(iKey) != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SG metrics seems to have an index https://github.com/NetApp/harvest/blob/main/cmd/collectors/storagegrid/storagegrid.go#L219

Would getting by name work?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, validated locally and it's able to apply the given operator on the same instance of both metrics.

mat.NewInstance(metricName + "-" + strconv.Itoa(i)); Yes, it has index in instanceKey generation, but we use that instance key as-is for all m arrays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MetricAgent crashes with nil pointer dereference on StorageGRID Prometheus collector

3 participants